import Vue from 'vue'
import Router from 'vue-router'

//登录
import login from "../views/login/toLogin.vue";
import register from "../views/login/register.vue";
import Layout from "../views/layout/index.vue"

Vue.use(Router)


const originalReplace = Router.prototype.replace
// 修改 原型对象中的replace方法
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err=>err)
}

const routes = [
  {
    path: "/",
    redirect: '/login'
  },
  //登录
  {
    path: '/login',
    name: "login",
    component: login,
    meta: {
      title: '登录'
    },
  },
  // 注册
  { path: '/register', name: "register", component: register },
  // 忘记密码
  { path: '/resetPassword', name: "resetPassword", component: register },
  // 首页
  {
    path: '/home',
    component: Layout,
    children: [
      {path: '', component: () => import('../views/home'), name: 'home', meta: { title: '首页'}},
    ]
  },
  {
    path: '/account',
    component: Layout,
    meta: { title: '账号管理',},
    children: [
      {path: '/contact', component: () => import('../views/account/contact_info'), name: 'contact_info', meta: { title: '联系人信息'}},
      {path: '/address', component: () => import('../views/account/address'), name: 'address', meta: { title: '发货地'}},
      {path: '/setupPassword', component: () => import('../views/account/setupPassword'), name: 'setupPassword', meta: { title: '设置密码'}},
      {path: '/applyAccount', component: () => import('../views/account/apply_account'), name: 'apply_account', meta: { title: '申请子账号'}},
      {path: '/news', component: () => import('../views/account/my_news'), name: 'my_news', meta: { title: '我的消息'}},
      {path: '/myAttentions', component: () => import('../views/account/myAttentions'), name: 'myAttentions', meta: { title: '我的关注'}},
    ]
  },
  {
    path: '/purchase',
    component: Layout,
    meta: { title: '采购管理',},
    children: [
      {path: '/publish_purchase', component: () => import('../views/purchase/publish_purchase'), name: 'publish_purchase', meta: { title: '发布采购'}},
      {path: '/purchase_list', component: () => import('../views/purchase/purchase_list'), name: 'purchase_list', meta: { title: '采购列表'}},
      {path: '/purchase_hangqing', component: () => import('../views/purchase/purchase_hangqing'), name: 'purchase_hangqing', meta: { title: '原料行情'}},
      {path: '/purchase_hangqing_detail', component: () => import('../views/purchase/purchase_hangqingDetail'), name: 'purchase_hangqing_detail', meta: { title: '原料行情'}},
    ]
  },
  {
    path: '/business',
    component: Layout,
    meta: { title: '企业管理',},
    children: [
      {path: '/supplier_enter', component: () => import('../views/business/supplier_enter'), name: 'supplier_enter', meta: { title: '入驻供应商'}},
      {path: '/set_store', component: () => import('../views/business/set_store'), name: 'set_store', meta: { title: '商铺设置'}},
      
      {path: '/issue_supply', component: () => import('../views/business/issue_supply'), name: 'issue_supply', meta: { title: '发布供应'}},

      {path: '/online_products', component: () => import('../views/business/online_products'), name: 'online_products', meta: { title: '已上线产品'}},
      {path: '/offline_products', component: () => import('../views/business/offline_products'), name: 'offline_products', meta: { title: '已下线产品'}},
    ]
  },
  {
    path: '/marketing',
    component: Layout,
    meta: { title: '营销管理',},
    children: [
      {path: '/message_marketing', component: () => import('../views/marketing/message_marketing'), name: 'message_marketing', meta: { title: '短信营销'}},
      {path: '/advertisement_putting', component: () => import('../views/marketing/advertisement_putting'), name: 'advertisement_putting', meta: { title: '广告投放'}},
    ]
  },
  {
    path: '/serve',
    component: Layout,
    meta: { title: '优塑服务',},
    children: [
      {path: '/connect_customerService', component: () => import('../views/serve/connect_customerService'), name: 'connect_customerService', meta: { title: '联系客服'}},
      {path: '/support_center', component: () => import('../views/serve/support_center'), name: 'support_center', meta: { title: '帮助中心'}},
      {path: '/problem_details', component: () => import('../views/serve/problem_details'), name: 'problem_details', meta: { title: '问题详情'}},
      {path: '/feedback', component: () => import('../views/serve/feedback'), name: 'feedback', meta: { title: '反馈意见'}},
      {path: '/accountEdit', component: () => import('../views/serve/accountEdit'), name: 'feedback', meta: { title: '会员介绍'}}
    ]
  },
]

const router = new Router({
  mode: 'hash',
  routes
})

export default router
